package leetcode.part1;

import org.junit.Test;

public class S1702 {
    public String maximumBinaryString(String bianry) {
        char[] array = bianry.toCharArray();
        int j=0;
        for (int i = 0; i < array.length; i++) {
            if (array[i] == '0') {
                // 找到下一个0，利用操作2使这两0相邻，再利用操作1使00变成10
               while (j<=i||(j<array.length&&array[j]=='1')){
                   j++;
               }
                // 如果没有0就跳出循环
                if (j<array.length){
                    array[i]='1';
                    array[j]='1';
                    array[i+1]='0';

                }

            }
        }
        StringBuilder builder=new StringBuilder();
        for (char c : array) {
            builder.append(c);
        }
        return builder.toString();


    }

    @Test
    public void test() {
        String s = maximumBinaryString("1100");
        System.out.println(s);
    }
}
